﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.ExportToWeb.CUiExportToWebDialog
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System;
using System.CodeDom.Compiler;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Forms;
using System.Windows.Markup;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.Ui;
using Tecnomatix.Engineering.Ui.WPF;


namespace DnProcessSimulateCommands.ExportToWeb;

public class CUiExportToWebDialog : TxWindow, IComponentConnector
{
  private CApExportToWebViewModel _apVM;
  private bool _browseClicked;
  internal System.Windows.Controls.TextBox OutputLocationPicker;
  internal System.Windows.Controls.Button BrowseButton;
  internal System.Windows.Controls.CheckBox LoadBrowserCheckBox;
  internal System.Windows.Controls.Label LodSelectionLabel;
  internal System.Windows.Controls.ComboBox LODPicker;
  internal System.Windows.Controls.CheckBox ExportSimulationCheckBox;
  internal System.Windows.Controls.Label OperationPickerLabel;
  internal TxObjEditBoxControl OperationPicker;
  internal System.Windows.Controls.Button OKButton;
  internal System.Windows.Controls.Button CancelButton;
  private bool _contentLoaded;

  public CUiExportToWebDialog(ITxOperation operation)
  {
    this._apVM = new CApExportToWebViewModel();
    this.InitializeComponent();
    this.InitOperationPicker(operation);
    ((FrameworkElement) this).DataContext = (object) this._apVM;
  }

  private void InitOperationPicker(ITxOperation operation)
  {
    // ISSUE: unable to decompile the method.
  }

  private void OKButton_Click(object sender, RoutedEventArgs e)
  {
    string directoryName = Path.GetDirectoryName(this._apVM.OutputFileName);
    if (!Directory.Exists(directoryName))
    {
      TxMessageBox.Show(directoryName + CApExportToWebUtilities.GetResourceManager().GetString("ERROR_EXPORT_DIRECTORY_FAILED"), CApExportToWebUtilities.GetResourceManager().GetString("CMD_NAME"), MessageBoxButtons.OK, MessageBoxIcon.Hand);
    }
    else
    {
      if (!this._browseClicked && File.Exists(this._apVM.OutputFileName) && TxMessageBox.Show(this._apVM.OutputFileName + CApExportToWebUtilities.GetResourceManager().GetString("WARNING_OVERWRITE_FILE"), CApExportToWebUtilities.GetResourceManager().GetString("CMD_NAME"), MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.No)
        return;
      CApExportToWeb capExportToWeb = new CApExportToWeb(this._apVM);
      this._apVM.m_isOnRuntime = true;
      ((UIElement) this).IsEnabled = false;
      if (capExportToWeb.Launch())
      {
        this.StoreValuesToRegistry();
        ((Window) this).Close();
      }
      else
        ((UIElement) this).IsEnabled = true;
    }
  }

  private void CancelButton_Click(object sender, RoutedEventArgs e) => ((Window) this).Close();

  private void BrowseButton_Click(object sender, RoutedEventArgs e)
  {
    if (!this._apVM.BrowseOutput())
      return;
    this._browseClicked = true;
  }

  private void OperationPicker_TypeInvalid(object sender, EventArgs e)
  {
    this._apVM.CheckCanExecute();
  }

  private void OperationPicker_TypeValid(object sender, EventArgs e)
  {
    this._apVM.CheckCanExecute();
  }

  private void OperationPicker_Picked(object sender, TxObjEditBoxCtrl_PickedEventArgs args)
  {
    this._apVM.CheckCanExecute();
  }

  private void OperationPicker_IsEnabledChanged(object sender, DependencyPropertyChangedEventArgs e)
  {
    if (this.OperationPicker.IsEnabled)
    {
      this.OperationPicker.Focus();
    }
    else
    {
      this.OperationPicker.HideErrorWindow();
      this.OperationPicker.LoseFocus();
    }
  }

  private void OutputLoaction_TextChanged(object sender, TextChangedEventArgs e)
  {
    this._apVM.CheckCanExecute();
  }

  private void ExportSimulationCheckBox_Checked(object sender, RoutedEventArgs e)
  {
    this._apVM.CheckCanExecute();
  }

  private void ExportSimulationCheckBox_Unchecked(object sender, RoutedEventArgs e)
  {
    this._apVM.Operation = (ITxOperation) null;
    this.OperationPicker.Text = "";
    this._apVM.CheckCanExecute();
  }

  private void TxWindow_Loaded(object sender, RoutedEventArgs e)
  {
    ((Window) this).SizeToContent = SizeToContent.Height;
    ((FrameworkElement) this).MinHeight = ((FrameworkElement) this).ActualHeight;
    ((FrameworkElement) this).MaxHeight = ((FrameworkElement) this).ActualHeight;
    this.LoadValuesFromRegistry();
  }

  private void TxWindow_Closed(object sender, EventArgs e)
  {
    this._apVM = (CApExportToWebViewModel) null;
  }

  private void StoreValuesToRegistry()
  {
    CApExportToWebUtilities.StoreValuesToRegistry((TxWindow) this, this._apVM);
  }

  private void LoadValuesFromRegistry()
  {
    CApExportToWebUtilities.LoadValuesFromRegistry((TxWindow) this, ref this._apVM);
  }

  [DebuggerNonUserCode]
  [GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
  public void InitializeComponent()
  {
    if (this._contentLoaded)
      return;
    this._contentLoaded = true;
    System.Windows.Application.LoadComponent((object) this, new Uri("/DnProcessSimulateCommands;component/exporttoweb/cuiexporttowebdialog.xaml", UriKind.Relative));
  }

  [DebuggerNonUserCode]
  [GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
  [EditorBrowsable(EditorBrowsableState.Never)]
  void IComponentConnector.Connect(int connectionId, object target)
  {
    switch (connectionId)
    {
      case 1:
        ((Window) target).Closed += new EventHandler(this.TxWindow_Closed);
        ((FrameworkElement) target).Loaded += new RoutedEventHandler(this.TxWindow_Loaded);
        break;
      case 2:
        this.OutputLocationPicker = (System.Windows.Controls.TextBox) target;
        this.OutputLocationPicker.TextChanged += new TextChangedEventHandler(this.OutputLoaction_TextChanged);
        break;
      case 3:
        this.BrowseButton = (System.Windows.Controls.Button) target;
        this.BrowseButton.Click += new RoutedEventHandler(this.BrowseButton_Click);
        break;
      case 4:
        this.LoadBrowserCheckBox = (System.Windows.Controls.CheckBox) target;
        break;
      case 5:
        this.LodSelectionLabel = (System.Windows.Controls.Label) target;
        break;
      case 6:
        this.LODPicker = (System.Windows.Controls.ComboBox) target;
        break;
      case 7:
        this.ExportSimulationCheckBox = (System.Windows.Controls.CheckBox) target;
        this.ExportSimulationCheckBox.Checked += new RoutedEventHandler(this.ExportSimulationCheckBox_Checked);
        this.ExportSimulationCheckBox.Unchecked += new RoutedEventHandler(this.ExportSimulationCheckBox_Unchecked);
        break;
      case 8:
        this.OperationPickerLabel = (System.Windows.Controls.Label) target;
        break;
      case 9:
        this.OperationPicker = (TxObjEditBoxControl) target;
        ((UIElement) this.OperationPicker).IsEnabledChanged += new DependencyPropertyChangedEventHandler(this.OperationPicker_IsEnabledChanged);
        this.OperationPicker.TypeInvalid += new EventHandler(this.OperationPicker_TypeInvalid);
        this.OperationPicker.TypeValid += new EventHandler(this.OperationPicker_TypeValid);
        this.OperationPicker.Picked += new TxObjEditBoxCtrl_PickedEventHandler(this.OperationPicker_Picked);
        break;
      case 10:
        this.OKButton = (System.Windows.Controls.Button) target;
        this.OKButton.Click += new RoutedEventHandler(this.OKButton_Click);
        break;
      case 11:
        this.CancelButton = (System.Windows.Controls.Button) target;
        this.CancelButton.Click += new RoutedEventHandler(this.CancelButton_Click);
        break;
      default:
        this._contentLoaded = true;
        break;
    }
  }
}
